package com.wuzhipeng.xuechengcontent.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.wuzhipeng.xuechengbase.exception.XueChengPlusException;
import com.wuzhipeng.xuechengbase.model.PageParams;
import com.wuzhipeng.xuechengbase.model.PageResult;
import com.wuzhipeng.xuechengcontent.dao.CourseBase;
import com.wuzhipeng.xuechengcontent.dto.AddCourseDto;
import com.wuzhipeng.xuechengcontent.dto.CourseBaseInfoDto;
import com.wuzhipeng.xuechengcontent.dto.EditCourseDTO;
import com.wuzhipeng.xuechengcontent.dto.QueryCourseParamsDto;
import com.wuzhipeng.xuechengcontent.service.ICourseBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @description 课程信息编辑接口
 * @author wuzhiheng
 * @date 2025/3/20 11:29
 * @version 1.0
 */
@RequiredArgsConstructor
@RestController
@Slf4j
@RequestMapping("/content")
@Tag(name = "课程信息编辑接口",description = "提供课程信息的增删改查接口")
public class CourseBaseInfoController {
    private final ICourseBaseService courseBaseService;
    /**
     * 查询课程列表
     * @param pageParams 分页参数
     * @param queryCourseParams 查询条件
     * @return 分页结果
     */
    @PostMapping("/course/list")
    @Operation(summary = "查询课程列表", description = "根据查询条件查询课程列表")
    public PageResult<CourseBase> list(PageParams pageParams, @RequestBody(required = false) QueryCourseParamsDto queryCourseParams){
        log.info("查询课程列表，查询条件：{}", queryCourseParams);
        /*throw new XueChengPlusException("暂未开通");*/
        PageResult<CourseBase> pageResult =  courseBaseService.queryCourseBaseList(pageParams, queryCourseParams);
        return pageResult;
    }

    /**
     * 新增课程基础信息
     * @param addCourseDto 新增课程信息
     * @return 新增课程信息 dto
     */
    @Operation(summary = "新增课程基础信息",description = "新增课程基础信息")
    @PostMapping("/course")
    public CourseBaseInfoDto createCourseBase(@RequestBody AddCourseDto addCourseDto){
        //机构id，由于认证系统没有上线暂时硬编码
        Long companyId = 1232141425L;
        return courseBaseService.createCourseBase(companyId,addCourseDto);
    }

    /**
     * 查询课程基础信息
     * @param courseId 课程id
     * @return 课程基础信息 dto
     */
    @Operation(summary = "查询课程详情",description = "查询课程详情")
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDto getCourseBaseById(@PathVariable Long courseId){
        return courseBaseService.getCourseBaseInfo(courseId);
    }
    /**
     * 修改课程基础信息
     * @param editCourseDto 修改课程信息 dto
     * @return 修改后的课程信息 dto
     */
    @Operation(summary = "修改课程基础信息",description = "修改课程基础信息")
    @PutMapping("/course")
    public CourseBaseInfoDto modifyCourseBase(@RequestBody EditCourseDTO editCourseDto){
        //机构id，由于认证系统没有上线暂时硬编码
        Long companyId = 1232141425L;
        return courseBaseService.updateCourseBase(companyId,editCourseDto);
    }
}